﻿using UnityEngine;

namespace com.yd.sdk
{
    public class OtherSetting : ISetting
    {
        private bool _isRemoteConfig = false;
        private bool _isCloudMessaging = false;
        public void Init()
        {
            _isRemoteConfig = SDKEditorWindow.sdkSettings.isOpen_RemoteConfig;
        }

        public void OnGUI()
        {
            GUILayout.Label("其他模块");
            GUILayout.BeginHorizontal();
            _isRemoteConfig = GUILayout.Toggle(_isRemoteConfig, "Firebase-RemoteConfig");
            _isCloudMessaging = GUILayout.Toggle(_isCloudMessaging, "Firebase-CloudMessaging(测试)");
            GUILayout.EndHorizontal();
        }

        public void Apply()
        {
            if (_isRemoteConfig)
                InstallRemoteConfig();
            else
                RemoveRemoteConfig();
            SDKEditorWindow.sdkSettings.isOpen_RemoteConfig = _isRemoteConfig;
        }
        
        public bool IsSelectedSomething()
        {
            return _isRemoteConfig;
        }

        private void InstallRemoteConfig()
        {
            //向Gradle中添加依赖库
            Utils.MergeDependenciesInGradle(Constants.GetFullPath(Constants.ANDROID_MAIN_TEMPLATE_PATH),
                Constants.FIREBASE_REMOTECONFIG_DEPENDENCIES);
            //实现库
            Utils.MergeDependenciesInGradle(Constants.GetFullPath(Constants.ANDROID_MAIN_TEMPLATE_PATH),
                Constants.FIREBASE_REMOTECONFIG_IMP_DEPENDENCIES);
        }
        
        private void RemoveRemoteConfig()
        {
            Utils.DeleteStringFromFile(Constants.GetFullPath(Constants.ANDROID_MAIN_TEMPLATE_PATH),
                "\t" + Constants.FIREBASE_REMOTECONFIG_DEPENDENCIES + "\r");
            Utils.DeleteStringFromFile(Constants.GetFullPath(Constants.ANDROID_MAIN_TEMPLATE_PATH),
                "\t" + Constants.FIREBASE_REMOTECONFIG_IMP_DEPENDENCIES + "\r");
        }
    }
}


